package com.bom.boot.easy.entity;

import com.bom.boot.easy.core.comment.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;


@Data
@Entity(name = "ops_option")
@Comment("页面操作表")
public class OptionEntity {

    @EmbeddedId
    private OptionId id;

    @Comment("页面标题")
    private String title;

    @Comment("操作方式")
    @Enumerated(EnumType.STRING)
    private OptionTypeEnum type;

    @OneToMany(mappedBy = "id.option", cascade = CascadeType.ALL)
    private Set<OptionInEntity> optionIns = new HashSet<>();

    @OneToMany(mappedBy = "id.option", cascade = CascadeType.ALL)
    private Set<OptionOutEntity> optionOuts = new HashSet<>();

    @Comment("数据库")
    private String ds;
    @Comment("执行")
    private String key;

    @EqualsAndHashCode(exclude = "page")
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Embeddable
    public static class OptionId implements Serializable {
        @Comment("页面信息")
        @ManyToOne
        @JoinColumn(name = "page_name", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
        private PageEntity page;

        @Comment("操作信息")
        private String name;
    }

    public enum OptionTypeEnum {
        ADD, UPDATE, DEL, SEARCH, LIST, DETAIL
    }
}
